﻿using System;
using System.Collections.Generic;
using System.Text;

namespace University
{
    class Course
    {
        private Dictionary<int, Student> enrolled;
        public string Name { get; private set; }

        public void AddStudent(Student student)
        {
            if (student == null)
            {
                throw new ArgumentNullException("Parameter student must not be null");
            }
            int key = student.FacultyNumber;
            if (enrolled.ContainsKey(key))
            {
                string errorMessage = string.Format("Student {0} is already enrolled.", key);
                throw new ArgumentOutOfRangeException();
            }
            if (enrolled.Count >= 30)
            {
                throw new Exception("Course too big.");
            }

            enrolled.Add(key, student);
        }

        public void RemoveStudent(Student student)
        {
            int key = student.FacultyNumber;
            if (!enrolled.ContainsKey(key))
            {
                string errorMessage = string.Format("Student {0} was not enrolled.", key);
                throw new ArgumentOutOfRangeException(errorMessage);
            }
            enrolled.Remove(key);
        }

        public Student FindStudent(int facultyNumber)
        {
            return enrolled[facultyNumber];
        }

        public bool ContainsStudent(Student student)
        {
            if (student == null)
            {
                throw new ArgumentNullException("Student should not be null");
            }
            return enrolled.ContainsKey(student.FacultyNumber);
        }

        public Course(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("Course name can not be null.");
            }
            if (name == "")
            {
                throw new ArgumentOutOfRangeException("Course name can not be empty.");
            }

            this.Name = name;
            enrolled = new Dictionary<int, Student>();
        }
    }
}
